package com.fengzhi.crawler._51job;

import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;

public class LinkQueue {

	// 已访问url
	private static Set<String> visitedURL = new HashSet<String>();

	// 待访问url
	private static Queue<String> unVisitedURL = new PriorityQueue<String>();

	/**
	 * 
	 * @Description: TODO(添加访问过的url)
	 * @param url
	 */
	public static void addVisitedURL(String url) {
		visitedURL.add(url);
	}

	/**
	 * 
	 * @Description: TODO(移除访问过的url)
	 * @param url
	 */
	public static void removeVisitedURL(String url) {
		visitedURL.remove(url);
	}

	/**
	 * 
	 * @Description: TODO(获取url队列)
	 * @return
	 */
	public static Queue<String> getUnVisitedURL() {
		return unVisitedURL;
	}

	/**
	 * 
	 * @Description: TODO(未访问的url出队列)
	 * @return
	 */
	public static String unVisitedURLDeQueue() {
		return unVisitedURL.poll();
	}

	/**
	 * 
	 * @Description: TODO(未访问的Url，判断url是否已经呗访问，保证每个url只被访问一次)
	 * @param url
	 */
	public static void addUnVisitedURL(String url) {
		if (url != null && !"".equals(url.trim()) && !visitedURL.contains(url) && !unVisitedURL.contains(url)) {
			unVisitedURL.add(url);
		}
	}

	/**
	 * 
	 * @Description: TODO(已访问的url数目)
	 * @return
	 */
	public static int getVisitedURLSize() {
		return visitedURL.size();
	}

	/**
	 * 
	 * @Description: TODO(判断未访问的url队列中是否为空)
	 * @return
	 */
	public static boolean isUnVisitedURLsEmpty() {
		return unVisitedURL.isEmpty();
	}

	public static Set<String> getVisitedURL() {
		return visitedURL;
	}

}
